{% extends 'base.html' %}

{% block content %}
<div class="container mt-4">
    <div class="row justify-content-center">
        <div class="col-md-8">
            <div class="card">
                <div class="card-header bg-primary text-white">
                    <h4 class="mb-0">{{ title }}</h4>
                </div>
                <div class="card-body">
                    <form method="post">
                        {% csrf_token %}
                        {% if form.non_field_errors %}
                        <div class="alert alert-danger">
                            {% for error in form.non_field_errors %}
                            {{ error }}
                            {% endfor %}
                        </div>
                        {% endif %}

                        <div class="mb-3">
                            <label for="{{ form.subject.id_for_label }}" class="form-label">学科</label>
                            {{ form.subject }}
                            {% if form.subject.errors %}
                            <div class="text-danger">
                                {{ form.subject.errors }}
                            </div>
                            {% endif %}
                        </div>

                        <div class="mb-3">
                            <label for="{{ form.name.id_for_label }}" class="form-label">章节名称</label>
                            {{ form.name }}
                            {% if form.name.errors %}
                            <div class="text-danger">
                                {{ form.name.errors }}
                            </div>
                            {% endif %}
                        </div>

                        <div class="mb-3">
                            <label for="{{ form.description.id_for_label }}" class="form-label">描述</label>
                            {{ form.description }}
                            {% if form.description.errors %}
                            <div class="text-danger">
                                {{ form.description.errors }}
                            </div>
                            {% endif %}
                        </div>

                        <div class="mb-3">
                            <label for="{{ form.order.id_for_label }}" class="form-label">排序</label>
                            {{ form.order }}
                            <div class="form-text">数字越小越靠前显示</div>
                            {% if form.order.errors %}
                            <div class="text-danger">
                                {{ form.order.errors }}
                            </div>
                            {% endif %}
                        </div>

                        <div class="d-flex justify-content-between">
                            <a href="{% url 'core:subject_chapter_knowledge' subject_id %}" class="btn btn-outline-secondary">取消</a>
                            <button type="submit" class="btn btn-primary">保存</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}